import http from "@/api";

import { PORT1 } from "@/api/config/servicePort";

export type DataOptionType = {
  value: string | number;
  label: string;
  // 属性输入类型 1 单选  2 多选  3 文本  4 多行文本  5 数值
  prop_type?: 1 | 2 | 3 | 4 | 5;
};

//获取初始化属性 + 属性值
export const initAttribute = (params?: any, queueId?: string) => {
  return http.post<{ dataarr: Record<string, DataOptionType[]>; defaults: Record<string, any> }>(
    `${PORT1}/goods-config/mergeProp/edit-merge-prop/index`,
    params,
    { loading: false, queueId }
  );
};

// 获取合并属性值列表
export const getAttributeList = (data: Record<string, any>, queueId?: string) =>
  http.post<{ dataarr: Record<string, DataOptionType[]>; defaults: Record<string, any> }>(
    `${PORT1}/goods-config/mergeProp/edit-merge-prop/propval-list`,
    { ...data },
    { loading: false, queueId }
  );

//获取属性
export const getAttribute = (params?: any) => {
  return http.post<{ [k: string]: DataOptionType[] }>(`${PORT1}/goods-config/mergeProp/edit-merge-prop/get-prop`, params, {
    loading: false
  });
};

//获取属性值
export const getPropval = (params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}/goods-config/mergeProp/edit-merge-prop/get-propval`, params, {
    loading: false
  });
};

//创建合并属性
export const setMergeAttribute = (params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}/goods-config/mergeProp/edit-merge-prop/create`, params, { loading: false });
};

// 编辑合并属性
export const editMergeAttribute = (data: Record<string, any>, queueId?: string) =>
  http.post(`${PORT1}/goods-config/mergeProp/edit-merge-prop/edit-prop`, { ...data }, { loading: false, queueId });

// 编辑合并属性值
export const editMergeAttributeValue = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-config/mergeProp/edit-merge-prop/edit-propval`, { ...data }, { loading: false });
